package com.elm.orders.controller;
import com.elm.common.pojo.Result;
import com.elm.orders.pojo.Orders;
import com.elm.orders.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/orders")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @PostMapping("/create")
    public Result<Integer> createOrders(@RequestBody Orders orders){
        Integer id=ordersService.createOrders(orders);
        if (id!=0){
            return Result.success(id);
        }
        return Result.error("创建订单失败");
    }

    @GetMapping("/getById")
    public Result<Orders> getOrdersById(@RequestParam Integer orderId){
        Orders orders=ordersService.getOrdersById(orderId);
        return Result.success(orders);
    }

    @GetMapping("/listByUserId")
    public Result<List<Orders>> listOrdersByUserId(@RequestParam String userId){
        List<Orders> list=ordersService.listOrdersByUserId(userId);
        return Result.success(list);
    }

    @PutMapping("/update")
    public Result update(@RequestParam Integer orderId){
        ordersService.update(orderId);
        return Result.success();
    }
}
